﻿using Aliyun.OSS;
using XYS.Core.Models;
using XYS.Service.Core.Models;
using XYS.Service.Core.Models.Enum;

namespace XYS.Service.Core.Service
{
    /// <summary>
    /// 对象存储 接口
    /// </summary>
    public interface IOSSService
    {
        /// <summary>
        /// 配置项
        /// </summary>
        OSSSetting OSSSetting { get; }

        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="localFilename">本地文件路径</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns>文件在OSS中的完整路径</returns>
        ResultModel<FilePutResult> Put(FilePutRequest req, string localFilename, EnumOSSACLType aclType = EnumOSSACLType.Default);

        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="fileStream">文件流</param>
        /// <param name="localFilename">文件名</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns>文件在OSS中的完整路径</returns>
        ResultModel<FilePutResult> Put(FilePutRequest req, Stream fileStream, string localFilename, EnumOSSACLType aclType = EnumOSSACLType.Default);

        /// <summary>
        /// 远程上传
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="remoteUrl">文件的远程地址</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns></returns>
        ResultModel<FilePutResult> RemotePut(FilePutRequest req, string remoteUrl, EnumOSSACLType aclType = EnumOSSACLType.Default);


        /// <summary>
        /// 远程上传
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="remoteUrl">文件的远程地址</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns></returns>
        ResultModel<FilePutResult> RemotePutNoWait(FilePutRequest req, string remoteUrl, EnumOSSACLType aclType = EnumOSSACLType.Default);

        /// <summary>
        /// 远程上传
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="remoteUrl">文件的远程地址</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns></returns>
        ResultModel<FilePutResult> RemotePutWait(FilePutRequest req, string remoteUrl, EnumOSSACLType aclType = EnumOSSACLType.Default);

        /// <summary>
        /// 获取文件连接
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        ResultModel<string> GeneratePresignedUri(GeneratePresignedUriReq req);

        /// <summary>
        /// 获取文件连接
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        ResultModel<List<GeneratePresignedUriResult>> GeneratePresignedUri(List<Models.GeneratePresignedUriRequest> req);


        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="req"></param>
        /// <param name="localFilename"></param>
        /// <returns></returns>
        ResultModel DownLoad(FileDownLoadRequest req, string localFilename);

        /// <summary>
        /// 上传文件 不等待上传完成（后台上传），直接返回结果
        /// </summary>
        /// <param name="req">上传参数</param>
        /// <param name="localFilename">本地文件路径</param>
        /// <param name="aclType">OSS 对象 ACL 类型</param>
        /// <returns>文件在OSS中的完整路径</returns>
        ResultModel<FilePutResult> PutNoWait(FilePutRequest req, string localFilename, EnumOSSACLType aclType = EnumOSSACLType.Default);

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        ResultModel Delete(DeleteOssFileRequest request);



        /// <summary>
        /// 读取对象的ACL
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        CannedAccessControlList? GetACL(string bucketName, string path);
        /// <summary>
        /// 设置对象的ACL
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="path"></param>
        /// <param name="acl"></param>
        /// <returns></returns>
        ResultModel SetACL(string bucketName, string path, CannedAccessControlList acl);
    }
}